// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.assets.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.assets.controller.request.QueryAssetsSpreadReq;
import com.liuxinlong.modules.assets.service.AssetsSpreadService;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 固资管理控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023-10-30
 */
@RestController
@RequestMapping("/assets/spread")
public class AssetsSpreadController {
    @Autowired
    private AssetsSpreadService assetsSpreadService;

    /**
     * 查询固资首页
     *
     * @param req 请求信息
     * @return 固资首页信息
     */
    @PostMapping("page")
    public BaseResp pageAssetsDashboard(@RequestBody QueryAssetsSpreadReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("type", req.getType());
        queryMap.put("year", req.getCurrentYear());
        queryMap.put("quarter", req.getQuarter());
//        queryMap.put("projectType", req.getProjectType());
//        queryMap.put("status", req.getStatus());
        Map<String, Object> dataMap = assetsSpreadService.getAssetsDashboard(queryMap,req.getType());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询固资首页信息成功");
        resp.setDataMap(dataMap);
        return resp;
    }

    /**
     * 导出固资首页信息
     *
     * @param response response
     * @return 导出数据
     */
    @PostMapping("export")
    @LogAnnotation(value = "导出固资首页信息", business = LogBusinessConstants.ASSETS_MANAGEMENT, operateType = LogOperateConstants.OPERATE_EXPORT)
    public void exportAssetsBudget(@RequestBody QueryBaseReq req, HttpServletResponse response) {
        assetsSpreadService.exportAssetsBudget(response);
    }

    /**
     * 查询部门年度花费
     *
     * @param req 请求信息
     * @return 部门年度花费
     */
    @PostMapping("department-page")
    public BaseResp pageAssetsDepDetail(@RequestBody QueryAssetsSpreadReq req) {
        Map<String, Object> dataMap = assetsSpreadService.pageAssetsDepDetail(req.getCurrentYear(),req.getDepartment());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询部门年度花费信息成功");
        resp.setDataMap(dataMap);
        return resp;
    }
}
